import express from 'express';
import { aiRecommendationController } from '../controllers/aiRecommendationController';
import { roleAuth } from '../middleware/roleAuth';
import { Role } from '@prisma/client';
import { validateRequest } from '../middleware/validation';
import { z } from 'zod';

const router = express.Router();

// 验证Schema
const studentIdSchema = z.object({
  params: z.object({
    studentId: z.string().uuid('无效的学生ID')
  })
});

const recommendationRequestSchema = z.object({
  params: z.object({
    studentId: z.string().uuid('无效的学生ID')
  }),
  query: z.object({
    subject: z.string().min(1, '学科不能为空')
  })
});

const learningPathRequestSchema = z.object({
  params: z.object({
    studentId: z.string().uuid('无效的学生ID')
  }),
  body: z.object({
    subject: z.string().min(1, '学科不能为空'),
    targetTopic: z.string().min(1, '目标知识点不能为空')
  })
});

// 获取个性化学习建议路由
router.get(
  '/:studentId/personalized',
  roleAuth([Role.ADMIN, Role.TEACHER, Role.STUDENT]),
  validateRequest(recommendationRequestSchema),
  aiRecommendationController.getPersonalizedRecommendations
);

// 获取学习路径建议路由
router.post(
  '/:studentId/learning-path',
  roleAuth([Role.ADMIN, Role.TEACHER, Role.STUDENT]),
  validateRequest(learningPathRequestSchema),
  aiRecommendationController.getLearningPathRecommendations
);

// 获取建议历史路由
router.get(
  '/:studentId/history',
  roleAuth([Role.ADMIN, Role.TEACHER, Role.STUDENT]),
  validateRequest(studentIdSchema),
  aiRecommendationController.getRecommendationHistory
);

export default router;
